package com.decent.web.system.dao.provider;

import com.decent.web.system.dto.SystemGoodsDTO;

import java.util.Map;

/**
 * @author: decent Gjh
 * @date: 2022/10/26/9:51
 * @description:
 */

public class SystemGoodsDaoProvider {

    /**
     * 列表查询
     * @param params 查询条件
     * @return 结果
     */
    public String list(Map<String, SystemGoodsDTO> params) {
        SystemGoodsDTO dto = params.get("goods");
        StringBuilder sql = new StringBuilder(128);
        sql.append("select * from common_goods ");
        if (dto == null) {
            return sql.toString();
        }
        sql.append("where 1 = 1 ");
        if (dto.getBrandId()!=null&&dto.getBrandId()!=0){
            sql.append("and brand_id = #{goods.brandId} ");
        }
        if (dto.getStockBool()!=null && dto.getStockBool()){
            sql.append(" and stock >0 ");
        }
        if (dto.getSortOrder() == null){
            return sql.toString();
        }
        //排序方式
        switch (dto.getSortOrder()) {
            case PRICE_SORT_ASC:
                sql.append("order by present_price ");
                break;
            case PRICE_SORT_DESC:
                sql.append("order by present_price desc ");
                break;
            case DISCOUNT_SORT_ASC:
                sql.append("order by present_price/original_price ");
                break;
            case DISCOUNT_SORT_DESC:
                sql.append("order by present_price/original_price desc ");
                break;
            default:
                break;
        }
        return sql.toString();
    }

}
